unit pList;

interface

type
  pelement=^element;
  element=record
    value: Integer;
    next: pelement;
  end;

var
  head: pelement;
  num: Integer;

implementation

procedure AddToBegin (var head: pelement; num: Integer);
var  tmp: pelement;
begin
  tmp:=head;
  New (head);
  head^.value:=num;
  head^.next:=tmp;
end;

procedure AddToEnd (var head: pelement; num: Integer);
begin
  if (head<>nil) then
  begin
    if (head=nil) then
    begin
      AddToBegin(head, num);
    end else begin
      AddToEnd(head^.next, num);
    end;

  end;
end;

procedure PrintList (head: pelement);
var
  current: pelement;
begin
  current:=head;
  while (current<>nil) do
  begin
    Writeln (current^.value);
    current:=current^.next;
  end;
end;

procedure DeleteFromBegin (var head: pelement);
var
  tmp: pelement;
begin
  tmp:=head^.next;
  Dispose (head);
  head:=tmp;
end;

procedure DeleteFromEnd (var head: pelement);
var
  current: pelement;
begin
  while (current^.next<>nil) do
    current:=current^.next;
  Dispose (current);
  current:=nil;
end;


end.
